//
//  MTOpenRedpackDetailCell.swift
//  MT
//
//  Created by ooops on 2019/12/24.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTOpenRedpackDetailCell: UITableViewCell {
    
    class func reuseIdentity() -> String {
        return "MTOpenRedpackDetailCellID"
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        makeConstraint()
        selectionStyle = .none
        contentView.backgroundColor = .white
    }
    
    var listModel: MTOpenRedpackResultListModel? {
        didSet {
            if listModel != nil {
                avatorImageView.mtSetImage(listModel!.headHref, nil)
                nameLabel.text = listModel?.nickname
                moneyLabel.text = "\(listModel!.pullMoney!)点券"
            }
        }
    }
    
    private func setupUI() {
        contentView.addSubview(avatorImageView)
        contentView.addSubview(nameLabel)
        contentView.addSubview(moneyLabel)
        contentView.addSubview(lineView)
    }
    
    private func makeConstraint() {
        avatorImageView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10.auto())
            make.width.height.equalTo(44.auto())
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(avatorImageView.snp.right).offset(11.auto())
            make.right.equalTo(moneyLabel.snp.left).offset(-10.auto()).priority(.low)
        }
        
        moneyLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-16.auto())
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
    }
    
    lazy var avatorImageView: UIImageView = {
        let imageV = UIImageView()
        imageV.layer.cornerRadius = 22.auto()
        imageV.layer.masksToBounds = true
        imageV.contentMode = .scaleAspectFill
        return imageV
    }()
    
    lazy var nameLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCRegularFont(14)
        l.textColor = UIColor.black
        l.text = "IAN-伊恩啦啦啦"
        moneyLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
        return l
    }()
    
    lazy var moneyLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(16)
        l.textColor = UIColor.text.x1d1a1a
        l.text = "IAN-伊恩啦啦啦"
        l.textAlignment = .right
        return l
    }()
    
    lazy var lineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor.seprateLine.x707070
        return v
    }()
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
